//
//  DiscountCell.m
//  婚礼纪  首页
//
//  Created by 太阳 on 15/5/16.
//  Copyright (c) 2015年 三人. All rights reserved.
//

#import "DiscountCell.h"
#import "RecommendModel.h"
#import "ConnectionModel.h"
#import "UIImageView+WebCache.h"
@implementation DiscountCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellAccessoryNone;
        self.myscroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width / 1.422)];
//        [self.myscroll setBackgroundColor:[UIColor greenColor]];
        [self addSubview:self.myscroll];
        [self requestNet];
    }
    return self;
}
- (void)requestNet
{
    [ConnectionModel connectDoneWithStr:@"http://hunliji.com/v1/api/app/works/discount" block:^(NSData *data) {
        self.bigarray = [NSMutableArray array];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *array = [dic objectForKey:@"works"];
        for (NSDictionary *seconddic in array) {
            RecommendModel *model = [[RecommendModel alloc]init];
            [model setValuesForKeysWithDictionary:seconddic];
            [self.bigarray addObject:model];
        }
        [self createview];
    }];
}
- (void)createview
{
    int i = 0;
    for (RecommendModel *model in self.bigarray) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i *( [UIScreen mainScreen].bounds.size.width) + 50, 10, [UIScreen mainScreen].bounds.size.width - 100, ([UIScreen mainScreen].bounds.size.width - 100) / 1.18)];
//        [view setBackgroundColor:[UIColor yellowColor]];
        
        UIImageView *imageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 100, ([UIScreen mainScreen].bounds.size.width - 100 / 1.18 - 112))];
        
        //        [imageview setBackgroundColor:[UIColor blueColor]];
        [imageview sd_setImageWithURL:[NSURL URLWithString:model.cover_path] placeholderImage:nil options:SDWebImageRetryFailed];
        [view addSubview:imageview];
        
        UILabel *title =[[UILabel alloc]initWithFrame:CGRectMake(10, ([UIScreen mainScreen].bounds.size.width - 100 / 1.18 - 112) + 5, [UIScreen mainScreen].bounds.size.width - 120, 30)];
        title.font = [UIFont systemFontOfSize:17];
        title.text = [NSString stringWithFormat:@"%@", model.title];
        title.textColor = [UIColor colorWithWhite:0.4 alpha:1];
//        [title setBackgroundColor:[UIColor orangeColor]];
        [view addSubview:title];
        
        UILabel *market_price = [[UILabel alloc]initWithFrame:CGRectMake(10, ([UIScreen mainScreen].bounds.size.width - 100 / 1.18 - 112) + 30, 168, 20)];
        market_price.textColor = [UIColor colorWithWhite:0.6 alpha:0.8];
        market_price.font = [UIFont systemFontOfSize:15];
//        market_price.text = @"回想那一天想起的喜悦";
        market_price.text = [NSString stringWithFormat:@"市场价 ￥%@",model.market_price];
//        [market_price setBackgroundColor:[UIColor redColor]];
        [view addSubview:market_price];
        
        NSDictionary *dic =@{NSFontAttributeName:[UIFont systemFontOfSize:15]};
        CGRect rect = [market_price.text boundingRectWithSize:CGSizeMake(30, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(62, ([UIScreen mainScreen].bounds.size.width - 100 / 1.18 - 112) + 30, rect.size.width + 60, 20)];
        label.textColor = [UIColor colorWithWhite:0.6 alpha:0.8];
        label.text = @"–––––––";
        label.numberOfLines = 1;
        [view addSubview:label];
        
        
        
        UILabel *actual_price = [[UILabel alloc]initWithFrame:CGRectMake(190,  ([UIScreen mainScreen].bounds.size.width - 100 / 1.18 - 112) + 30, 75, 20)];
        NSString *str = [NSString stringWithFormat:@"￥%@", model.actual_price];
        actual_price.text = str;
        actual_price.font = [UIFont systemFontOfSize:20];
        actual_price.textColor = [UIColor colorWithRed:0.9 green:0.2 blue:0.2 alpha:1];
//        [actual_price setBackgroundColor:[UIColor blackColor]];
        
        [view addSubview:actual_price];
        
        view.layer.borderWidth = 0.5;
        view.layer.borderColor = [UIColor lightGrayColor].CGColor;
        
        
        [self.myscroll addSubview:view];
        i ++;
        self.myscroll.contentSize = CGSizeMake(i * ([UIScreen mainScreen].bounds.size.width), 0);
        self.myscroll.pagingEnabled = YES;

    }

}














@end
